package com.ryan.security.async;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Created by kaimin on 1/1/2019.
 * time : 14:29
 */
//模拟消息队列
@Data
@Slf4j
@Component
public class MockQueue {

    //下单的
    private String placeOrder;

    //订单完成的
    private String completeOrder;

    public String getPlaceOrder() {
        return placeOrder;
    }

    public void setPlaceOrder(String placeOrder) {
      new Thread(()->{
          log.info("接到下单请求");
          try {
              Thread.sleep(3000);//模拟下单过程
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          this.completeOrder = placeOrder;
          log.info("下单请求处理完成");
      }).start();

        //这段代码是在另外一个应用中的，所以模拟个线程
       /* System.out.println("接到下单请求");
        try {
            Thread.sleep(3000);//模拟下单过程
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.completeOrder = placeOrder;
        System.out.println("下单请求处理完成");*/
    }

    public String getCompleteOrder() {
        return completeOrder;
    }

    public void setCompleteOrder(String completeOrder) {
        this.completeOrder = completeOrder;
    }
}
